<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>适配器模式</title>
  </head>
  <body>
    <p>旧接口格式和使用者不兼容，中间加一个适配器进行兼容</p>
    <p>
      <img src="uml1.png" alt="" />
    </p>
    <p>
      <img src="uml2.png" alt="" />
    </p>
    <p>
      使用场景：<br />
      封装旧接口<br />
      vue computed
    </p>
    <script>
      class Adaptee {
        specificeRequest() {
          return "外国标准插头";
        }
      }

      class Target {
        constructor() {
          this.adaptee = new Adaptee();
        }
        request() {
          let info = this.adaptee.specificeRequest();
          return `${info} => 转换器 => 中国标准插头`;
        }
      }

      let target = new Target();
      let res = target.request();
      console.log(res);
    </script>
  </body>
</html>
